package com.wolf.etl.controller;

import com.wolf.etl.model.EtlApiModel;
import com.wolf.etl.service.IEtlApiService;
import com.wolf.provider.order.info.PageBean;
import com.wolf.system.model.SysUser;
import com.wolf.vo.PageQueryParam;
import com.wolf.vo.PageResult;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author sdyang
 * @date 2019/12/2 10:31
 **/
@RestController
@RequestMapping("/etl/api")
public class EtlApiController extends BaseController {

    private static Logger logger = LoggerFactory.getLogger(EtlApiController.class);

    @Autowired
    private IEtlApiService apiService;

    @GetMapping(value = "/list")
    public ModelAndView list() {
        ModelAndView model = new ModelAndView();
        model.setViewName("/etl/etl_api");
        model.addObject("currentUrl", "/etl/api/list");
        SysUser sysUser = userService.getSessionSysUser();
        model.addObject("sysUser", sysUser);
        model.addObject("currentTitle", "API");
        return model;

    }

    @RequestMapping(value = "/pagelist")
    public PageResult list(PageQueryParam queryParam) {

        PageBean pageBean = new PageBean();
        pageBean.setStart(queryParam.getStart());
        pageBean.setPageSize(queryParam.getLength());

        EtlApiModel model = new EtlApiModel();
        if (StringUtils.isNotEmpty(queryParam.getQueryData())) {
            JSONObject jsonParams = JSONObject.fromObject(queryParam.getQueryData());


        }

        PageResult result = apiService.findByPage(model, pageBean);
        result.setDraw(queryParam.getDraw());

        return result;
    }

}
